﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utilities;
using NetLib.web;

namespace StockImport.dataimport.tse.dailyindex
{
    public class Tse_DailyIndexFetcher
    {
        public static List<List<String>> Fetch(DateTime d, out  DateTime realDate)
        {
            String url = String.Format("http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/genpage/Report{0}/A112{1}ALLBUT0999_1.php?select2=ALLBUT0999&chk_date={2}", DateUtils.getYYYYMMPlanString(d), DateUtils.getPlanString(d), DateUtils.getROCString(d));
            String content = HttpGet.requestBig5(url);
            if (content.StartsWith("Error"))
            {
                throw new Exception(content);
            }
            DateTime l_realDate = DateTime.Now;
            List<List<String>> rows = Tse_DailyIndexParser.processDailyTradeDataByHtml(content, ref l_realDate);
            realDate = l_realDate;
            if (rows == null)
            {
                throw new Exception("No valid Rows");
            }
            content = "";
            return rows;
        }
    }
}
